package br.com.arg.aplica.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import br.com.arg.aplica.util.Utils;

@Entity 
@XmlRootElement
public class Classe implements Serializable {
	/** Default value included to remove warning. Remove or modify at will. **/
	private static final long serialVersionUID = 1L;

	public Classe()
	{
		this.setAtributos(new ArrayList<Atributo>());
		this.setRegras(new ArrayList<Regra>());
		this.setClasses(new ArrayList<Classe>());

		this.nome = "NovaClasseZ";
		this.descricao = "Descriçao da novaClasseZ";
		this.dataCriacao = Utils.setData("hoje");
		this.versao = "1.1";
	}
	
	@Id
	@GeneratedValue
	private Long id;

	@NotNull
	@Size(min = 1, max = 64)
	private String nome;
	
	@NotNull
	@Size(min = 1, max = 255)
	private String descricao;

	@NotNull
	private Date dataCriacao;

	@NotNull
	@Size(max = 10)
	@Pattern(regexp = "[0-9.-]*", message = "Somente numero . e -")
	private String versao;

	//**********************************
	@OneToOne(cascade = CascadeType.ALL)
    private Tela tela;

	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
  private List<Atributo> atributos;
	
	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Regra> regras;

	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Classe> classes;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public Date getDataCriacao() {
		return dataCriacao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public String getVersao() {
		return versao;
	}

	public void setVersao(String versao) {
		this.versao = versao;
	}

	public Tela getTela() {
		return tela;
	}

	public void setTela(Tela tela) {
		this.tela = tela;
	}

	public List<Atributo> getAtributos() {
		return atributos;
	}

	public void setAtributos(List<Atributo> atributos) {
		this.atributos = atributos;
	}

	public List<Regra> getRegras() {
		return regras;
	}

	public void setRegras(List<Regra> regras) {
		this.regras = regras;
	}

	public List<Classe> getClasses() {
		return classes;
	}

	public void setClasses(List<Classe> classes) {
		this.classes = classes;
	}	
}
